<template>
  <u-tabs-swiper
    :list="list"
    :current="current"
    :is-scroll="false"
    bar-width="65"
    font-size="28"
    inactive-color="#666666"
    active-color="#19B1B8"
    swiperWidth="750"
    :offset="[8, 50]"
    @change="tabsChange"
  ></u-tabs-swiper>
</template>

<script>
import { myTaskTotal } from "@/api/task";
export default {
  props: ["current"],
  data() {
    return {
      list: [
        { status: 10, name: "进行中", count: 0 },
        { status: 25, name: "已完成", count: 0 },
        { status: 21, name: "退稿/终止", count: 0 },
      ],
    };
  },
  mounted() {
    this.getTotal();
  },
  methods: {
    // 获取总条数
    getTotal() {
      for (let a = 0; a < this.list.length; a++) {
        this.list[a].count = 0;
      }
      myTaskTotal().then((res) => {
        if (res.success) {
          const { data } = res;
          for (let i = 0; i < data.length; i++) {
            let { num, taskStatus } = data[i];
            for (let j = 0; j < this.list.length; j++) {
              if (taskStatus == this.list[j].status) {
                this.list[j].count = num <= 99 ? num : "99+";
              }
            }
          }
        }
      });
    },
    tabsChange(index) {
      this.$emit("listenTabChange", index);
    },
  },
};
</script>